package com.jeethink.erp.buy.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jeethink.common.annotation.Log;
import com.jeethink.common.core.controller.BaseController;
import com.jeethink.common.core.domain.AjaxResult;
import com.jeethink.common.enums.BusinessType;
import com.jeethink.erp.buy.domain.TbBuy;
import com.jeethink.erp.buy.service.ITbBuyService;
import com.jeethink.common.utils.poi.ExcelUtil;
import com.jeethink.common.core.page.TableDataInfo;

/**
 * 进货Controller
 * 
 * @author ypr
 * @date 2021-05-31
 */
@RestController
@RequestMapping("/erp/buy")
public class TbBuyController extends BaseController
{
    @Autowired
    private ITbBuyService tbBuyService;

    /**
     * 查询进货列表
     */
    @PreAuthorize("@ss.hasPermi('erp:buy:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbBuy tbBuy)
    {
        startPage();
        List<TbBuy> list = tbBuyService.selectTbBuyList(tbBuy);
        return getDataTable(list);
    }

    /**
     * 导出进货列表
     */
    @PreAuthorize("@ss.hasPermi('erp:buy:export')")
    @Log(title = "进货", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbBuy tbBuy)
    {
        List<TbBuy> list = tbBuyService.selectTbBuyList(tbBuy);
        ExcelUtil<TbBuy> util = new ExcelUtil<TbBuy>(TbBuy.class);
        return util.exportExcel(list, "buy");
    }

    /**
     * 获取进货详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:buy:query')")
    @GetMapping(value = "/{buyId}")
    public AjaxResult getInfo(@PathVariable("buyId") Long buyId)
    {
        return AjaxResult.success(tbBuyService.selectTbBuyById(buyId));
    }

    /**
     * 新增进货
     */
    @PreAuthorize("@ss.hasPermi('erp:buy:add')")
    @Log(title = "进货", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbBuy tbBuy)
    {
        return toAjax(tbBuyService.insertTbBuy(tbBuy));
    }

    /**
     * 修改进货
     */
    @PreAuthorize("@ss.hasPermi('erp:buy:edit')")
    @Log(title = "进货", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbBuy tbBuy)
    {
        return toAjax(tbBuyService.updateTbBuy(tbBuy));
    }

    /**
     * 删除进货
     */
    @PreAuthorize("@ss.hasPermi('erp:buy:remove')")
    @Log(title = "进货", businessType = BusinessType.DELETE)
	@DeleteMapping("/{buyIds}")
    public AjaxResult remove(@PathVariable Long[] buyIds)
    {
        return toAjax(tbBuyService.deleteTbBuyByIds(buyIds));
    }
}
